split
and join
¶split
¶'Here are some words'.split()
['Here', 'are', 'some', 'words']
for word in 'here are some words'.split():
print(word)
here are some words
print('Do you know \n the \t muffin \n man?'.split())
['Do', 'you', 'know', 'the', 'muffin', 'man?']
cats.py
🐈 🐈⬛¶join
¶' '.join(['red', 'fish', 'blue', 'fish'])
'red fish blue fish'
" :) ".join(['red', 'fish', 'blue', 'fish'])
'red :) fish :) blue :) fish'
seuss = ['red', 'fish', 'blue', 'fish']
fish = '🐟'
fish.join(seuss)
'red🐟fish🐟blue🐟fish'
cougars.py
¶'House,Favorite place,School,Major'.split(',')
['House', 'Favorite place', 'School', 'Major']
'white,BYU,BYU,Computer Science'.split(',')
['white', 'BYU', 'BYU', 'Computer Science']
unemployment.py
¶The file unemployment.txt
looks like this:
State/Area Year Month %_Unemployed
Alabama 1976 1 6.6
Alaska 1976 1 7.1
Arizona 1976 1 10.2
Arkansas 1976 1 7.3
California 1976 1 9.2
Los-Angeles-County 1976 1 8.9
Write a program that takes a file like unemployment.txt
and a state and prints the maximum unemployment observed for that state.
What are the different list patterns you might use?
The file unemployment.txt
looks like this:
State/Area Year Month %_Unemployed
Alabama 1976 1 6.6
Alaska 1976 1 7.1
Arizona 1976 1 10.2
Arkansas 1976 1 7.3
California 1976 1 9.2
Los-Angeles-County 1976 1 8.9
Write a program that takes a file like unemployment.txt
and a year and prints the average unemployment observed for that year.
What are the different list patterns you might use?
What other questions can YOU answer with this data?
split
join